package demoArray

import (
	"fmt"
)

func DemoArray() [1][3]string {
	a := [...]int{1, 2, 3}

	doubleArray := [1][3]string{
		{"1", "2", "3"},
	}
	fmt.Println(a)
	//fmt.Println(doubleArray)
	return doubleArray
}

// golang切片
func demoSlice() {
	//var fslice []int

	// 声明一个含有10个元素元素类型为byte的数组
	var ar = [10]string{
		"a", string('b'), string('c'), string('d'), string('e'), string('f'), string('g'), string('h'), string('i'), string('j'),
	}

	// 声明两个含有byte的slice
	var a, b []string

	// a指向数组的第3个元素开始，并到第五个元素结束，
	a = ar[2:5]
	//现在a含有的元素: ar[2]、ar[3]和ar[4]

	// b是数组ar的另一个slice
	b = ar[3:5]
	// b的元素是：ar[3]和ar[4]

	//append(b, "ll")
	fmt.Printf("%v\n", a)
	fmt.Println(b)
	fmt.Println(len(b), cap(b))

}

func demoMap() {
	var numbers map[string]int

	numbers = make(map[string]int)
	numbers["one"] = 1
	numbers["two"] = 2
	numbers["one"] = 22
	fmt.Println(numbers)

	rating := map[string]float32{
		"C":   5,
		"D":   6,
		"C++": 7,
	}
	csharp, err := rating["C++"]
	if err {
		fmt.Println("error", csharp)
	} else {
		fmt.Println("We have no rating associated with C# in the map")
	}
	delete(rating, "C")
	fmt.Println(rating)

}

func Index() {
	arr := DemoArray()
	fmt.Println(arr)
	demoSlice()
	demoMap()
}
